<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>l8w8jwt: include/l8w8jwt/util.h File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="doxygen-awesome.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectalign">
   <div id="projectname">l8w8jwt
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.8 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li><li class="navelem"><a class="el" href="dir_4cc40c4817b6dd8b994fc53e2126ebc6.html">l8w8jwt</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#define-members">Macros</a> &#124;
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle"><div class="title">util.h File Reference</div></div>
</div><!--header-->
<div class="contents">

<p>Useful utility functions.  
<a href="#details">More...</a></p>
<div class="textblock"><code>#include &lt;stdlib.h&gt;</code><br />
<code>#include &lt;stddef.h&gt;</code><br />
<code>#include &quot;<a class="el" href="version_8h_source.html">version.h</a>&quot;</code><br />
</div><div class="textblock"><div class="dynheader">
Include dependency graph for util.h:</div>
<div class="dyncontent">
<div class="center"><img src="util_8h__incl.png" border="0" usemap="#ainclude_2l8w8jwt_2util_8h" alt=""/></div>
<map name="ainclude_2l8w8jwt_2util_8h" id="ainclude_2l8w8jwt_2util_8h">
<area shape="rect" title="Useful utility functions." alt="" coords="56,5,197,32"/>
<area shape="rect" title=" " alt="" coords="5,80,69,107"/>
<area shape="poly" title=" " alt="" coords="112,35,66,72,63,68,109,30"/>
<area shape="rect" title=" " alt="" coords="93,80,160,107"/>
<area shape="poly" title=" " alt="" coords="129,33,129,64,124,64,124,33"/>
<area shape="rect" href="version_8h.html" title="l8w8jwt version checking." alt="" coords="184,80,256,107"/>
<area shape="poly" title=" " alt="" coords="144,30,193,68,190,73,141,35"/>
</map>
</div>
</div>
<p><a href="util_8h_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="define-members" name="define-members"></a>
Macros</h2></td></tr>
<tr class="memitem:af97536f5f161b3a61ed52026de1ffb0c" id="r_af97536f5f161b3a61ed52026de1ffb0c"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="util_8h.html#af97536f5f161b3a61ed52026de1ffb0c">L8W8JWT_PLATFORM_MALLOC_ALT</a>&#160;&#160;&#160;0</td></tr>
<tr class="separator:af97536f5f161b3a61ed52026de1ffb0c"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a3f786a68ef741d7b6c4f539f1fb3e7a2" id="r_a3f786a68ef741d7b6c4f539f1fb3e7a2"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="util_8h.html#a3f786a68ef741d7b6c4f539f1fb3e7a2">L8W8JWT_PLATFORM_CALLOC_ALT</a>&#160;&#160;&#160;0</td></tr>
<tr class="separator:a3f786a68ef741d7b6c4f539f1fb3e7a2"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a7ffcf1b2873b30788a96e3f8f9dd916c" id="r_a7ffcf1b2873b30788a96e3f8f9dd916c"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="util_8h.html#a7ffcf1b2873b30788a96e3f8f9dd916c">L8W8JWT_PLATFORM_REALLOC_ALT</a>&#160;&#160;&#160;0</td></tr>
<tr class="separator:a7ffcf1b2873b30788a96e3f8f9dd916c"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a26780bf856e50344542e3d13ee9da7e2" id="r_a26780bf856e50344542e3d13ee9da7e2"><td class="memItemLeft" align="right" valign="top"><a id="a26780bf856e50344542e3d13ee9da7e2" name="a26780bf856e50344542e3d13ee9da7e2"></a>
#define&#160;</td><td class="memItemRight" valign="bottom"><b>l8w8jwt_malloc</b>&#160;&#160;&#160;malloc</td></tr>
<tr class="separator:a26780bf856e50344542e3d13ee9da7e2"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a43f916789171f24e184b20c6d8850b5e" id="r_a43f916789171f24e184b20c6d8850b5e"><td class="memItemLeft" align="right" valign="top"><a id="a43f916789171f24e184b20c6d8850b5e" name="a43f916789171f24e184b20c6d8850b5e"></a>
#define&#160;</td><td class="memItemRight" valign="bottom"><b>l8w8jwt_calloc</b>&#160;&#160;&#160;calloc</td></tr>
<tr class="separator:a43f916789171f24e184b20c6d8850b5e"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a1727460828867f0eda4095903ff9c44a" id="r_a1727460828867f0eda4095903ff9c44a"><td class="memItemLeft" align="right" valign="top"><a id="a1727460828867f0eda4095903ff9c44a" name="a1727460828867f0eda4095903ff9c44a"></a>
#define&#160;</td><td class="memItemRight" valign="bottom"><b>l8w8jwt_realloc</b>&#160;&#160;&#160;realloc</td></tr>
<tr class="separator:a1727460828867f0eda4095903ff9c44a"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:a744d5faba6c1ead8611bd615527b11f3" id="r_a744d5faba6c1ead8611bd615527b11f3"><td class="memItemLeft" align="right" valign="top">L8W8JWT_API int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="util_8h.html#a744d5faba6c1ead8611bd615527b11f3">l8w8jwt_hexstr2bin</a> (const char *hexstr, size_t hexstr_length, unsigned char *output, size_t output_size, size_t *output_length)</td></tr>
<tr class="separator:a744d5faba6c1ead8611bd615527b11f3"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a45ca6b04ce77733549bc4317987477c1" id="r_a45ca6b04ce77733549bc4317987477c1"><td class="memItemLeft" align="right" valign="top">L8W8JWT_API int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="util_8h.html#a45ca6b04ce77733549bc4317987477c1">l8w8jwt_strncmpic</a> (const char *str1, const char *str2, size_t n)</td></tr>
<tr class="separator:a45ca6b04ce77733549bc4317987477c1"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a80db9d7b369945ea853fe4ddece9f3f2" id="r_a80db9d7b369945ea853fe4ddece9f3f2"><td class="memItemLeft" align="right" valign="top">L8W8JWT_API int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="util_8h.html#a80db9d7b369945ea853fe4ddece9f3f2">l8w8jwt_memcmp</a> (const void *mem1, const void *mem2, size_t n)</td></tr>
<tr class="separator:a80db9d7b369945ea853fe4ddece9f3f2"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Useful utility functions. </p>
<dl class="section author"><dt>Author</dt><dd>Raphael Beck </dd></dl>
</div><h2 class="groupheader">Macro Definition Documentation</h2>
<a id="a3f786a68ef741d7b6c4f539f1fb3e7a2" name="a3f786a68ef741d7b6c4f539f1fb3e7a2"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a3f786a68ef741d7b6c4f539f1fb3e7a2">&#9670;&#160;</a></span>L8W8JWT_PLATFORM_CALLOC_ALT</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define L8W8JWT_PLATFORM_CALLOC_ALT&#160;&#160;&#160;0</td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Set this pre-processor definition to <code>1</code> if you need to provide custom implementation of calloc </p>

</div>
</div>
<a id="af97536f5f161b3a61ed52026de1ffb0c" name="af97536f5f161b3a61ed52026de1ffb0c"></a>
<h2 class="memtitle"><span class="permalink"><a href="#af97536f5f161b3a61ed52026de1ffb0c">&#9670;&#160;</a></span>L8W8JWT_PLATFORM_MALLOC_ALT</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define L8W8JWT_PLATFORM_MALLOC_ALT&#160;&#160;&#160;0</td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Set this pre-processor definition to <code>1</code> if you need to provide custom implementation of malloc </p>

</div>
</div>
<a id="a7ffcf1b2873b30788a96e3f8f9dd916c" name="a7ffcf1b2873b30788a96e3f8f9dd916c"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a7ffcf1b2873b30788a96e3f8f9dd916c">&#9670;&#160;</a></span>L8W8JWT_PLATFORM_REALLOC_ALT</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define L8W8JWT_PLATFORM_REALLOC_ALT&#160;&#160;&#160;0</td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Set this pre-processor definition to <code>1</code> if you need to provide custom implementation of realloc </p>

</div>
</div>
<h2 class="groupheader">Function Documentation</h2>
<a id="a744d5faba6c1ead8611bd615527b11f3" name="a744d5faba6c1ead8611bd615527b11f3"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a744d5faba6c1ead8611bd615527b11f3">&#9670;&#160;</a></span>l8w8jwt_hexstr2bin()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">L8W8JWT_API int l8w8jwt_hexstr2bin </td>
          <td>(</td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>hexstr</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t&#160;</td>
          <td class="paramname"><em>hexstr_length</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">unsigned char *&#160;</td>
          <td class="paramname"><em>output</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t&#160;</td>
          <td class="paramname"><em>output_size</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t *&#160;</td>
          <td class="paramname"><em>output_length</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Converts a hex-encoded string to a binary array. </p>
<p>A NUL-terminator is appended at the end of the output buffer, so make sure to allocate at least <code>(hexstr_length / 2) + 1</code> bytes! </p><dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">hexstr</td><td>The hex string to convert. </td></tr>
    <tr><td class="paramname">hexstr_length</td><td>Length of the <code>hexstr</code> </td></tr>
    <tr><td class="paramname">output</td><td>Where to write the converted binary data into. </td></tr>
    <tr><td class="paramname">output_size</td><td>Size of the output buffer (make sure to allocate at least <code>(hexstr_length / 2) + 1</code> bytes!). </td></tr>
    <tr><td class="paramname">output_length</td><td>[OPTIONAL] Where to write the output array length into. This is always gonna be <code>hexstr_length / 2</code>, but you can still choose to write it out just to be sure. If you want to omit this: no problem.. just pass <code>NULL</code>! </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd><code>0</code> if conversion succeeded. <code>1</code> if one or more required arguments were <code>NULL</code> or invalid. <code>2</code> if the hexadecimal string is in an invalid format (e.g. not divisible by 2). <code>3</code> if output buffer size was insufficient (needs to be at least <code>(hexstr_length / 2) + 1</code> bytes). </dd></dl>

</div>
</div>
<a id="a80db9d7b369945ea853fe4ddece9f3f2" name="a80db9d7b369945ea853fe4ddece9f3f2"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a80db9d7b369945ea853fe4ddece9f3f2">&#9670;&#160;</a></span>l8w8jwt_memcmp()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">L8W8JWT_API int l8w8jwt_memcmp </td>
          <td>(</td>
          <td class="paramtype">const void *&#160;</td>
          <td class="paramname"><em>mem1</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const void *&#160;</td>
          <td class="paramname"><em>mem2</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t&#160;</td>
          <td class="paramname"><em>n</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Compares two blocks of memory against equality in a cryptographically safe manner (time-safe impl./constant-time comparison). </p><dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">mem1</td><td>Memory block 1 to compare. </td></tr>
    <tr><td class="paramname">mem2</td><td>Memory block 2 to compare. </td></tr>
    <tr><td class="paramname">n</td><td>How many bytes to compare. </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Returns <code>0</code> if the two memory blocks are equal for the passed amount of bytes. </dd></dl>

</div>
</div>
<a id="a45ca6b04ce77733549bc4317987477c1" name="a45ca6b04ce77733549bc4317987477c1"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a45ca6b04ce77733549bc4317987477c1">&#9670;&#160;</a></span>l8w8jwt_strncmpic()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">L8W8JWT_API int l8w8jwt_strncmpic </td>
          <td>(</td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>str1</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>str2</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t&#160;</td>
          <td class="paramname"><em>n</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Compares two strings ignoring UPPER vs. lowercase. </p><dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">str1</td><td>String to compare. </td></tr>
    <tr><td class="paramname">str2</td><td>String to compare to. </td></tr>
    <tr><td class="paramname">n</td><td>How many characters of the string should be compared (starting from index 0)? </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>If the strings are equal, <code>0</code> is returned. Otherwise, something else. </dd></dl>

</div>
</div>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.8
</small></address>
</body>
</html>
